package com.easyaop.api.aopalliance;

import com.easyaop.api.around.Around;
import com.easyaop.api.around.Call;
import com.easyaop.api.join.JoinPoint;
import org.aopalliance.intercept.MethodInterceptor;

/**
 * @Description :
 * @Create on : 2025/5/13 09:31
 * @author albert
 **/
public class MethodInterceptorHandler implements Around {
    private final MethodInterceptor methodInterceptor;

    public MethodInterceptorHandler(MethodInterceptor methodInterceptor) {
        this.methodInterceptor = methodInterceptor;
    }

    @Override
    public Object around(Object target, Object[] args, JoinPoint joinPoint, Call call) throws Exception {
        try {
            return this.methodInterceptor.invoke(new DefaultMethodInvocation(target,args,joinPoint,call));
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}
